<?php
require_once('./admin/connexion.php');
require ('./func.req.php');
if ($install) {
    header("Location:./install/index.php");
} else {
    require('./config/tbl.php');
    if ($line_info['maintenance_choix_info'] == "Oui") {
        show_maintenance();
    } else {
        /*
          -----------------------------------
          ---- SCRIPT D'AUTHENTIFICATION ----
          FujiCraft V3.0
          By Fujido
          Contact : thefujido@gmail.com
          -----------------------------------
         */

        session_start(); // On relaye la session
        if (@session_is_registered("authentification")) { // v�rification sur la session authentification (la session est elle enregistr�e ?)
            // ici les �ventuelles actions en cas de r�ussite de la connexion
        } else {
            header("Location:login.php?erreur=needlog"); // redirection en cas d'echec
        }

        // GESTION DE LA D�connexion
        if (isset($_GET['erreur']) && $_GET['erreur'] == 'logout') { // Test sur les param�tres d'URL qui permettront d'identifier un "contexte" de d�connexion
            $prenom = $_SESSION['prenom']; // On garde le pr�nom en variable pour dire au revoir (soyons polis :-)
            @session_unset("authentification");
            header("Location:login.php?erreur=logout");
        }
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title><?php echo $site; ?> | Mon Profil</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <meta http-equiv="Content-Style-Type" content="text/css" />
                <meta http-equiv="content-language" content="fr,en" />
                <link rel='shortcut icon' type="image/x-icon" href='./images/favicon.ico' />
                <link rel="stylesheet" type="text/css" href="./css/style.css" title="" media="all" />
                <link rel="stylesheet" type="text/css" href="./css/news.css" title="" media="all" />
                <link rel="stylesheet" type="text/css" href="./css/register.css" title="" media="all" />
                <script type="text/javascript" src="./js/news.js"></script>
            </head>
            <body>
                <div id="block">
                    <div id="contentblock">
                        <div class="wrapper">
                            <?php
                            show_header();
                            show_menu();
                            show_newsbox();
                            show_userbox();
                            ?>
                            <div class="mainbox">
                                <h2>Mon Profil</h2>
                                <br />
                                <center>
                                    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                        <?php
                                        if (isset($_POST['edit_profil'])) {
                                            $login = $_SESSION['login'];
                                            $pass = md5($_POST['pass']);
                                            $skype = mysql_escape_string($_POST['skype']);
                                            $pass_old = md5($_POST['pass_old']);
                                            if ($pass_old != "" && $pass_old == $_SESSION['pass'] && $_POST['pass'] == "" && $_POST['pass2'] == "") {
                                                $query_skype = "UPDATE " . $database . "." . $tb_utilisateurs . " SET skype = '$skype' WHERE login = '$login'";
                                                mysql_query($query_skype) OR DIE(mysql_error());
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="success-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Votre profil a bien &eacute;t&eacute; mit &agrave; jour. Afin que les changements prennent effets, vous devez vous d&eacute;connectez et vous reconnectez.
                                                </div>
                                                <?php
                                                show_user_profil();
                                            } else if ($pass_old != "" && $_POST['pass'] != "" && $_POST['pass2'] != "" && $pass != $pass_old && $_POST['pass'] == $_POST['pass2']) {
                                                $query_psw = "UPDATE " . $database . "." . $tb_utilisateurs . " SET pass = '$pass', skype = '$skype' WHERE login ='$login' ";
                                                mysql_query($query_psw) OR DIE(mysql_error());
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="success-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Votre mot de passe a bien &eacute;t&eacute; mit &agrave; jour.
                                                </div>
                                                <?php
                                                show_user_profil();
                                            } else if ($pass_old != "" && $_POST['pass'] != "" && $_POST['pass2'] != "" && $pass != $pass_old && $_POST['pass'] == $_POST['pass2']) {
                                                $query_psw = "UPDATE " . $database . "." . $tb_utilisateurs . " SET pass = '$pass', skype = '$skype' WHERE login ='$login' ";
                                                mysql_query($query_psw) OR DIE(mysql_error());
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="success-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Votre mot de passe a bien &eacute;t&eacute; mit &agrave; jour.
                                                </div>
                                                <?php
                                                show_user_profil();
                                            } else {
                                                ?>
                                                <div id="box" onclick="document.getElementById('box').style.display='none';" class="error-box rounded" title="Fermer la fen&ecirc;tre">
                                                    Veuillez remplir les champs ou au moins indiquez votre mot de passe actuel.
                                                </div>
                                                <?php
                                                show_user_profil();
                                            }
                                        } else {
                                            show_user_profil();
                                        }
                                        ?>
                                </center>
                            </div>
                            <?php show_footer(); ?>
                        </div>
                    </div>
                </div>
            </body>
        </html>
        <?php
    }
}
?>